/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.icm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import merlion.mrp.pmm.entity.FinishedGood;
import merlion.mrp.ppm.entity.Product;



/**
 *
 * @author Yuwei
 */

@Entity
public class ProductInventoryRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Long balance;//total qty including reserved and unreserved
    private Long reservedQty;
   // private Long availableQty;
    private Long optimalStock;
    @OneToOne(targetEntity = Product.class,cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Product product;
    @OneToMany(targetEntity = FinishedGood.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private List<FinishedGood> batches;

    //--------------------------------------------------------------------------
    //                              Entity Methods
    //--------------------------------------------------------------------------
    public ProductInventoryRecord(){
        balance = 0L;
        reservedQty = 0L;
        //availableQty = 0L;
        optimalStock = 1500L;
        product = null;
        batches = new ArrayList<FinishedGood>();
    }
    
    //--------------------------------------------------------------------------
    //                              Getter and Setter
    //--------------------------------------------------------------------------

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getBalance() {
        return balance;
    }

    public void setBalance(Long balance) {
        this.balance = balance;
    }

    

    public Long getOptimalStock() {
        return optimalStock;
    }

    public void setOptimalStock(Long optimalStock) {
        this.optimalStock = optimalStock;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public List<FinishedGood> getBatches() {
        return batches;
    }

    public void setBatches(List<FinishedGood> batches) {
        this.batches = batches;
    }

    public Long getReservedQty() {
        return reservedQty;
    }

    public void setReservedQty(Long reservedQty) {
        this.reservedQty = reservedQty;
    }


    //--------------------------------------------------------------------------
    //                              Other Methods
    //--------------------------------------------------------------------------

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ProductInventoryRecord)) {
            return false;
        }
        ProductInventoryRecord other = (ProductInventoryRecord) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.icm.entity.ProductInventoryRecord[ id=" + id + " ]";
    }
    
}
